package org.lql.chaos.rocketmq.callback;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author: liangqinglong
 * @date: 2025-08-16 21:12
 * @description: 统一发送回调
 **/
public class UnifiedSendCallback implements SendCallback {

	private static final Logger log = LoggerFactory.getLogger(UnifiedSendCallback.class);

	@Override
	public void onSuccess(SendResult sendResult) {
		log.info("消息发送成功，MsgId: {}", sendResult.getMsgId());
		// 统一的成功日志记录
	}

	@Override
	public void onException(Throwable throwable) {
		log.error("消息发送失败", throwable);

		// 根据异常类型进行不同处理
		if (throwable instanceof MQClientException) {
			// 客户端异常处理
			handleClientException((MQClientException) throwable);
		} else if (throwable instanceof MQBrokerException) {
			// Broker异常处理
			handleBrokerException((MQBrokerException) throwable);
		} else {
			// 其他异常处理
			handleOtherException(throwable);
		}
	}

	private void handleClientException(MQClientException exception) {
		// 客户端异常处理逻辑
	}

	private void handleBrokerException(MQBrokerException exception) {
		// Broker异常处理逻辑
	}

	private void handleOtherException(Throwable throwable) {
		// 其他异常处理逻辑
	}
}
